using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{
    /// <summary>表示Ajax操作结果</summary>
    public class AjaxResult
    {
        /// <summary>
        /// 初始化一个<see cref="T:OSharp.AspNetCore.UI.AjaxResult" />类型的新实例
        /// </summary>
        public AjaxResult()
            : this((string)null, AjaxResultType.Success, (object)null)
        {
        }

        /// <summary>
        /// 初始化一个<see cref="T:OSharp.AspNetCore.UI.AjaxResult" />类型的新实例
        /// </summary>
        public AjaxResult(string content, AjaxResultType type = AjaxResultType.Success, object data = null)
            : this(content, data, type)
        {
        }

        /// <summary>
        /// 初始化一个<see cref="T:OSharp.AspNetCore.UI.AjaxResult" />类型的新实例
        /// </summary>
        public AjaxResult(string content, object data, AjaxResultType type = AjaxResultType.Success)
        {
            this.Type = type;
            this.Content = content;
            this.Data = data;
        }

        /// <summary>获取或设置 Ajax操作结果类型</summary>
        public AjaxResultType Type { get; set; }

        /// <summary>获取或设置 消息内容</summary>
        public string Content { get; set; }

        /// <summary>获取或设置 返回数据</summary>
        public object Data { get; set; }

        /// <summary>是否成功</summary>
        public bool Successed()
        {
            return this.Type == AjaxResultType.Success;
        }

        /// <summary>是否错误</summary>
        public bool Error()
        {
            return this.Type == AjaxResultType.Error;
        }

        /// <summary>成功的AjaxResult</summary>
        public static AjaxResult Success(object data = null)
        {
            return new AjaxResult("操作执行成功", AjaxResultType.Success, data);
        }
    }
}
